set -e
# 部署环境 从脚本外部传递
deployEnv=$1

source $WORKSPACE/deploy/config.sh
source $WORKSPACE/deploy/utils.sh

# 初始化环境变量
initEnvVal
initPublishWorkspace

echo "-----------------构建项目名: $projectName -----------------"
echo "-----------------构建时间: $buildTime -----------------"
echo "-----------------构建环境: $deployEnv -----------------"
echo "-----------------构建镜像名: $iName -----------------"
echo "-----------------工作目录: $WORKSPACE -----------------"
echo "-----------------k8s命名空间: $k8sNs -----------------"
echo "-----------------部署配置文件路径: $k8sConfigPath -----------------"
echo "-----------------镜像拉取密钥key: $pullSercret -----------------"

build() {
	yarnInstall
	npm run build:$deployEnv
	mv ./dist dockerBuild/dist

	cp deploy/nginx-$deployEnv.conf ./dockerBuild/nginx.conf
	cp deploy/Dockerfile ./dockerBuild

	buildImage

	genK8sDeployYaml
	doK8sDeploy

}

build
echo "------------------- ${projectName} 构建完成 -------------------"
